/**
 * @author Vu Nguyen Hoang
 */
$(document).ready(function(){
	if ($("#box_search_keyword").attr("value") == null || $("#box_search_keyword").attr("value") == ""){
		$("#box_search_keyword").css("color","#96A5E9");		
		$("#box_search_keyword").attr("value", "Gõ tiếng Việt có dấu để tìm kiếm chính xác nhất");
	}	
	$("#box_search_keyword").click(function(){
		$("#box_search_keyword").attr("value", "");
		$("#box_search_keyword").css("color","#16387C");
	});
	$("#box_search_keyword").blur(function(){
		if ($("#box_search_keyword").attr("value") == null || $("#box_search_keyword").attr("value") == ""){
			$("#box_search_keyword").css("color","#96A5E9");
			$("#box_search_keyword").attr("value", "Gõ tiếng Việt có dấu để tìm kiếm chính xác nhất");
		}
	});
	if ($("#onlinkpayment_terms_agree").attr("checked") == false) {
		$("#onlinkpayment_card_holder_name").parent("td").parent("tr").css("display","none");
		$("#onlinkpayment_card_number_1").parent("td").parent("tr").css("display","none");
		$("#onnlinkpayment_expires_month").parent("td").parent("tr").css("display","none");
		$("#onlinkpayment_payment_method_internet").parent("td").parent("tr").css("display","none");
	} else {
		$("#onlinkpayment_card_holder_name").parent("td").parent("tr").css("display","");
		$("#onlinkpayment_card_number_1").parent("td").parent("tr").css("display","");
		$("#onnlinkpayment_expires_month").parent("td").parent("tr").css("display","");
		$("#onlinkpayment_payment_method_internet").parent("td").parent("tr").css("display","");
	}
	$("#onlinkpayment_terms_agree").click(function() {
		if (this.checked == false) {
			$("#onlinkpayment_card_holder_name").parent("td").parent("tr").css("display","none");
			$("#onlinkpayment_card_number_1").parent("td").parent("tr").css("display","none");
			$("#onnlinkpayment_expires_month").parent("td").parent("tr").css("display","none");
			$("#onlinkpayment_payment_method_internet").parent("td").parent("tr").css("display","none");
		} else {
			$("#onlinkpayment_card_holder_name").parent("td").parent("tr").css("display","");
			$("#onlinkpayment_card_number_1").parent("td").parent("tr").css("display","");
			$("#onnlinkpayment_expires_month").parent("td").parent("tr").css("display","");
			$("#onlinkpayment_payment_method_internet").parent("td").parent("tr").css("display","");
		}
	});
	$("#onlinkpayment_card_number_1").keyup(function() {
		if (this.value.length == 4) {
			$("#onlinkpayment_card_number_2").focus();
		}
	});
	$("#onlinkpayment_card_number_2").keyup(function() {
		if (this.value.length == 4) {
			$("#onlinkpayment_card_number_3").focus();
		}
	});
	$("#onlinkpayment_card_number_3").keyup(function() {
		if (this.value.length == 4) {
			$("#onlinkpayment_card_number_4").focus();
		}
	});
	$("#onlinkpayment_card_holder_name").keyup(function() {
		var str = this.value;
		this.value = str.toUpperCase();		
	});	
	$("#countries_list").change(function(){
		$("#zones_list").html('<option value="">Loading</option>');
		$.post("get_zones_for_country.php", {"country_id":this.value}, function(data) {
			if (data == '') {
				$("#zones_list").html('<option value=""><b>No information</b></option>');
				$("#districts_list").html('<option value="">No information</option>');
			} else {
				$("#zones_list").html(data);	
				$.post("get_districts_for_zone.php", {"zone_id":$("#zones_list").attr("value")}, function(data) {
					if (data == '') {
						$("#districts_list").html('<option value=\"\">No information</option>');
					} else {
						$("#districts_list").html(data);			
					}			
				});
			}
		});
	});
	$.post("get_zones_for_country.php", {"country_id":$("#countries_list").attr("value")}, function(data) {
		if (data == '') {
			$("#zones_list").html('<option value=""><b>No information</b></option>');
		} else {
			$("#zones_list").html(data);			
			$.post("get_districts_for_zone.php", {"zone_id":$("#zones_list").attr("value")}, function(data) {
				if (data == '') {
					$("#districts_list").html('<option value=\"\">No information</option>');
				} else {
					$("#districts_list").html(data);			
				}			
			});
		}
	});
	$("#zones_list").change(function(){
		$("#districts_list").html('<option value="">Loading</option>');
		$.post("get_districts_for_zone.php", {"zone_id":this.value}, function(data) {
			if (data == '') {
				$("#districts_list").html('<option value="">No information</option>');
		    } else {
				$("#districts_list").html(data);			
			}
		});
	});
	$.post("get_districts_for_zone.php", {"zone_id":$("#zones_list").attr("value")}, function(data) {
		if (data == '') {
			$("#districts_list").html('<option value="">No information</option>');
		} else {
			$("#districts_list").html(data);			
		}			
	});
	if ($("#create_account_agree_check").attr("checked") == false) {
		$("#create_account_countinue_buttion").css("display","none");		
	} else {
		$("#create_account_countinue_buttion")..css("display","");		
	}
	$("#create_account_agree_check").click(function() {
		if (this.checked == false) {
			$("#create_account_countinue_buttion").css("display","none");					
		} else {
			$("#create_account_countinue_buttion").css("display","");
		}
	});
});

